package thread;

/**
 *
 * 子线程如何获取父线程的值
 * @author 胡琦
 * @date 2022-04-21 星期四 19:53
 */
public class ThreadDemo1 {

    public static void main(String[] args) {
        new Thread(() -> {
            ThreadLocal threadLocal = new ThreadLocal();
            threadLocal.set(1);
            InheritableThreadLocal inheritableThreadLocal = new InheritableThreadLocal();
            inheritableThreadLocal.set(2);

            new Thread(() -> {
                System.out.println("threadLocal = " + threadLocal.get());
                System.out.println("inheritableThreadLocal = " + inheritableThreadLocal.get());
            }).start();

        }, "父线程").start();

        /**
         * threadLocal = null
         * inheritableThreadLocal = 2
         */

    }


}
